//package Day6;
//
//import javax.imageio.spi.ServiceRegistry;
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpSession;
//import java.io.IOException;
//import java.util.logging.LogRecord;
////@WebFilter("/index.jsp")
//public class Filter_1 implements Filter {
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//
//    }
// //拦截
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        //图片资源都需要放行 sevlet
//        String [] urls={"loginlogin.jsp","register.jsp","..."};
//
//        HttpServletRequest request=(HttpServletRequest) servletRequest;
//        //拿到用户请求路径
//      String url= request.getRequestURI().toString();
//        for (String u : urls) {
//            if(u.equals(url)){
//                filterChain.doFilter(servletRequest,servletResponse);
//                return ;
//            }
//        }
//
//        HttpSession session= request.getSession();
//        Object user=session.getAttribute("user");
//        if(user!=null)
//        {
//            filterChain.doFilter(servletRequest,servletResponse);
//        }
//        else{
//            request.setAttribute("","请登录");
//            request.getRequestDispatcher("/").forward(request,servletResponse);
//        }
//
//    }
//
//    @Override
//    public void destroy() {
//
//    }
//}
